package com.situ.mymall.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.mymall.mapper.CategoryMapper;
import com.situ.mymall.pojo.entity.Category;
import com.situ.mymall.pojo.query.CategoryQuery;
import com.situ.mymall.pojo.vo.CategoryCountVO;
import com.situ.mymall.service.ICategoryService;
import com.situ.mymall.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl implements ICategoryService {

    @Autowired
    private CategoryMapper categoryMapper;


    @Override
    public PageResult list(CategoryQuery categoryQuery) {
        PageHelper.startPage(categoryQuery.getPage(), categoryQuery.getLimit());
        List<Category> list = categoryMapper.list(categoryQuery);
        PageInfo pageInfo = new PageInfo(list);
        int totalCount = (int) pageInfo.getTotal();

        return PageResult.ok(totalCount,list);
    }

    @Override
    public Category selectById(Integer id) {
        return categoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public void addSelective(Category category) {
        categoryMapper.insertSelective(category);
    }

    @Override
    public void deleteById(Integer id) {
        categoryMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void deleteAll(Integer[] ids) {
        categoryMapper.deleteAll(ids);
    }

    @Override
    public void update(Category category) {
        categoryMapper.updateByPrimaryKeySelective(category);
    }

    @Override
    public List<Category> selectTopCategory() {
        return categoryMapper.selectTopCategory();
    }

    @Override
    public List<Category> selectSecondCategoryByTopCategoryId(Integer id) {
        return categoryMapper.selectSecondCategoryByTopCategoryId(id);
    }

    @Override
    public void updateStatus(Category category) {
        categoryMapper.updateStatus(category);
    }

    @Override
    public List<CategoryCountVO> echarts() {
        return categoryMapper.echarts();
    }


}
